//
//  WZOutCell.m
//  ETong
//
//  Created by wanzhao on 15/11/24.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZOutCell.h"


@interface WZOutCell ()

//文件按钮
@property (nonatomic, weak) UIButton *fileBtn;
//申请外出时间
@property (nonatomic, weak) UILabel *outApplyLabel;
//申请外出公司名
@property (nonatomic, weak) UILabel *companyNameLabel;
//申请外出地址
@property (nonatomic, weak) UILabel *outAddressLabel;

/**距离*/
@property (nonatomic, weak) UILabel *distanceLabel;

@property (nonatomic, weak) UIView *bgView;


@end

@implementation WZOutCell

+ (WZOutCell *)outCellWithTableView:(UITableView *)tableView
{
    static NSString *outCellId = @"outCellId";
    WZOutCell *cell = [tableView dequeueReusableCellWithIdentifier:outCellId];
    if (cell == nil) {
        cell = [[WZOutCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:outCellId];
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = ClearColor;
        self.contentView.backgroundColor = ClearColor;
        [self setUpSubViews];
    }
    return self;
}

- (void)setUpSubViews
{
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = WhiteColor;
    [self.contentView addSubview:bgView];
    self.bgView = bgView;
    
    UIButton *fileBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [fileBtn setImage:[UIImage imageNamed:@"outNormalFile"] forState:UIControlStateNormal];
    [fileBtn setImage:[UIImage imageNamed:@"outSelectedfile"] forState:UIControlStateSelected];
    fileBtn.userInteractionEnabled = NO;
    [bgView addSubview:fileBtn];
    self.fileBtn = fileBtn;
    
    UILabel *outApplyLabel = [[UILabel alloc] init];
    outApplyLabel.textColor = RGBCOLORWITH16COLOR(0x999999);
    outApplyLabel.font = Font12;
    outApplyLabel.numberOfLines = 0;
    [bgView addSubview:outApplyLabel];
    self.outApplyLabel = outApplyLabel;
    
    UILabel *companyNameLabel = [[UILabel alloc] init];
    companyNameLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    companyNameLabel.font = Font12;
    companyNameLabel.numberOfLines = 0;
    [bgView addSubview:companyNameLabel];
    self.companyNameLabel = companyNameLabel;

    UILabel *outAddressLabel = [[UILabel alloc] init];
    outAddressLabel.textColor = RGBCOLORWITH16COLOR(0x999999);
    outAddressLabel.numberOfLines = 0;
    outAddressLabel.font = Font12;
    [bgView addSubview:outAddressLabel];
    self.outAddressLabel = outAddressLabel;
    
    UILabel *distanceLabel = [[UILabel alloc] init];
    distanceLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    distanceLabel.font = Font12;
    distanceLabel.numberOfLines = 0;
    distanceLabel.text = [NSString stringWithFormat:@"%.1ld米", 10];
    [bgView addSubview:distanceLabel];
    self.distanceLabel = distanceLabel;
}

- (void)setOutFrame:(WZOutFrame *)outFrame
{
    _outFrame = outFrame;
    
    WZOut *wzOut = outFrame.wzOut;
    
    if (wzOut.outIsSelected) {
        self.fileBtn.selected = YES;
        self.bgView.layer.borderColor = RGBCOLORWITH16COLOR(0xf6bb43).CGColor;
        self.bgView.layer.borderWidth = 0.5f;
    } else {
        self.fileBtn.selected = NO;
        self.bgView.layer.borderColor = RGBCOLORWITH16COLOR(0xe0ddd8).CGColor;
        self.bgView.layer.borderWidth = 0.5f;

    }
    
    
    self.bgView.frame = outFrame.outBgFrame;
    
    self.fileBtn.frame = outFrame.outFileFrame;
    
    self.outApplyLabel.frame = outFrame.outApplyTimeFrame;
    self.outApplyLabel.text = [NSString stringWithFormat:@"申请外出时间 %@",wzOut.planBeginTime];
    
    self.companyNameLabel.frame = outFrame.outCompanyFrame;
    self.companyNameLabel.text = wzOut.customerName;
    
    self.outAddressLabel.frame = outFrame.outApplyAddressFrame;
    self.outAddressLabel.text = [NSString stringWithFormat:@"地址：%@",wzOut.outAddress];
    
    self.distanceLabel.frame = outFrame.distanceFrame;
    
    NSString *distance = 0;
    if (wzOut.distance < 1000) {
        distance = [NSString stringWithFormat:@"%d米", (int)wzOut.distance];
    } else {
        distance = [NSString stringWithFormat:@"%d千米", (int)wzOut.distance / 1000];

    }
    
    self.distanceLabel.text = distance;
}

//- (void)setDistance:(NSInteger)distance {
//    
//    _distance = distance;
//    
//    self.distance = distance;
//}

@end
